package com.pupil.down.util;

import com.pupil.down.system.SysSettings;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Description: 日志工具
 * @Author: pupil
 * @Date: 2024/09/28 下午 5:20
 */
public class LogUtil {

    private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");

    public static void info(String msg, Object... args) {
        print(msg, " --INFO-- ", args);
    }

    public static void error(String msg, Object... args) {
        print(msg, " --ERROR-- ", args);
    }

    public static void debug(String msg, Object... args) {
        if (SysSettings.DEBUG) {
            print(msg, " --DEBUG-- ", args);
        }
    }


    private static void print(String msg, String level, Object... args) {
        if (args != null && args.length > 0) {
            msg = String.format(msg.replace("{}", "%s"), args);
        }
        // 获取当前线程的名称
        String threadName = Thread.currentThread().getName();
        // 打印时间+线程名+日志级别+消息
        System.out.println(LocalDateTime.now().format(dateTimeFormatter) + " " + threadName + level + msg);
    }
}
